package org.mytools.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextHolder implements ApplicationContextAware {

	private static ApplicationContext webApplicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		webApplicationContext = applicationContext;
	}

	@SuppressWarnings(value = "unchecked")
	public static <T> T getBean(String name) {
		return (T) webApplicationContext.getBean(name);
	}

}
